#include <bits/stdc++.h>
using namespace std;

int t,n,m,cnt;
int lm,vm;
struct carn{
    int l,r;
    bool os;
}car[100005];
int p[100005];
int fa[100005];

void calcar(int id, int d, int v0, int a) {
    if (v0<=vm && a<=0) car[id].l=-1, car[id].r=-1;
    if (v0<=vm && a>0) {
        int x = (vm*vm-v0*v0) / (2*a);
        if ((vm*vm-v0*v0)%(2*a) == 0) x += 1;//special judge
        car[id].l = min(d+x,lm);//
        car[id].r = lm;
    }
    if (v0>vm && a>=0) car[id].l=d, car[id].r=lm;
    if (v0>vm && a<0) {
        int x = (vm*vm-v0*v0) / (2*a);
        if ((vm*vm-v0*v0)%(2*a) == 0) x -= 1;//sj
        car[id].l = d;
        car[id].r = min(d+x,lm);//
    }
    //printf("[%d:%d]\n", car[id].l, car[id].r);
    return ;
}

bool cmp(int a, int b) {return a<b;}

bool cmp2(carn a,carn b) {return a.r-a.l<b.r-b.l;}

int findfa(int x) {
    while (fa[x] != x) x = fa[x];
    return x;
}

int main() {
    freopen("detect.in","r",stdin);
    freopen("detect.out","w",stdout);
    cin >> t;
    for (int i=0; i<t; i++) {
        cin >> n >> m >> lm >> vm;
        int d0,v0,a;
        for (int j=1; j<=n; j++) {
            cin >> d0 >> v0 >> a;
            calcar(j, d0, v0, a);
        }
        for (int j=0; j<m; j++) {
            cin >> p[j];
        }
        sort(p,p+m,cmp);//cmp
        for (int j=1; j<=n; j++) {
            for (int k=0; k<m; k++) {
                if (p[k]>=car[j].l && p[k]<=car[j].r && !car[j].os) {
                    //cout << j << " ";
                    car[j].os = 1;
                    cnt ++;
                    break ;
                }
            }
        }
        cout << cnt << " ";

        int ans = n;
        sort(car+1,car+n+1,cmp2);
        for (int j=1; j<=n; j++) fa[j]=j;
        for (int j=1; j<=n; j++) {
            for (int k=1; k<=n; k++) {
                int ll = max(car[j].l,car[k].l);
                int rr = min(car[j].r,car[k].r);
                /*int bll = bs(ll),brr = bs(rr);
                if (bll<brr || ((bll==brr)&&(ll==rr)&&(ll==bll))) {
                    if (findfa(j) != findfa(k)) fa[k] = j;
                }*/
                for (int u=0; u<m; u++) {
                    if (p[u]<=rr && p[u]>=ll) {
                        if (findfa(k) != findfa(j)) {
                            fa[k] = j;
                            ans --;
                        }
                    }
                }
            }
        }
        cout << m - ans << endl;
        //for (int j=0; j<m; j++) cout << findfa(j) << " ";
    }
    fclose(stdin);
    fclose(stdout);
    return 0;
}
